/**
 * 输入一个链表，输出该链表中倒数第k个结点。
 */
public class Solution22 {
    public ListNode FindKthToTail(ListNode head, int k) {
        if (head == null || k <= 0) {
            return null;
        }

        ListNode fastNode = head;
        ListNode slowNode = head;
        for (int i = 1; i < k; i++) {
            if (fastNode.next == null) {
                return null;
            }
            fastNode = fastNode.next;
        }
        while (fastNode.next != null) {
            fastNode = fastNode.next;
            slowNode = slowNode.next;
        }
        return slowNode;
    }
}
